import HtmlGenerate from "./html_generate";
import TreeWalker from "../tree_walker";

export class MarkdownRender {
  render(mnode) {
    const htmlGenerate = new HtmlGenerate();
    const treeWalker = new TreeWalker(mnode);
    let buffer = "";
    let current;
    while ((current = treeWalker.next())) {
      if (htmlGenerate[current.mnode.type]) {
        buffer =
          htmlGenerate[current.mnode.type](
            buffer,
            current.mnode,
            current.close
          ) || "";
      }
    }
    return buffer;
  }
}

export default MarkdownRender;
